package com.disapand.strongarmy.model

import org.ktorm.database.*
import org.ktorm.entity.*
import org.ktorm.schema.*

/**
 * 用户对象
 *
 * @auth disapand
 * @date 2021/10/11 - 13:38 - 星期一
 *
 */
interface Account : BaseModel, Entity<Account> {
    companion object: Entity.Factory<Account>()

    var account: String
    var password: String
    var username: String
    var avatar: String
}

/**
 * 用户表
 */
open class Accounts(alias: String?) : Table<Account>("sa_account", alias) {
    companion object: Accounts(null)

    override fun aliased(alias: String) = Accounts(alias)

    val id = int("id").primaryKey().bindTo { it.id }
    val account = varchar("account").bindTo { it.account }
    val password = varchar("password").bindTo { it.password }
    val username = varchar("username").bindTo { it.username }
    val avatar = varchar("avatar").bindTo { it.avatar }
    val status = int("status").bindTo { it.status }
    val deleted = boolean("deleted").bindTo { it.deleted }
    val createdBy = int("created_by").bindTo { it.createdBy }
    val createdAt = datetime("created_at").bindTo { it.createdAt }
    val updatedBy = int("updated_by").bindTo { it.updatedBy }
    val updatedAt = datetime("updated_at").bindTo { it.updatedAt }
}

val Database.accounts get() = this.sequenceOf(Accounts)